package com.base.pig.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.base.pig.entity.ScSensorInfo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author yjh
 * @since 2022-04-19
 */
@Mapper
public interface ScSensorInfoMapper extends BaseMapper<ScSensorInfo> {

    //查询全部传感器id(---)
    @Select("  select sensor_code sensorCode from sc_sensor_info   ")
    List<Map<String,Object>> queryAllSensorCode();


    //查询类型对应传感器(---)
    @Select("    select  s.sensor_name sensorName ,s.sensor_code sensorCode,s.sensor_unit sensorUnit,s.sensor_metric sensorMetric,  ds.device_type  deviceType " +
            "    from    sc_type_sensor ds  , sc_sensor_info  s " +
            "    where    s.sensor_code=ds.sensor_code " +
            "    and  ds.device_type=#{devicetype}  ")
    List<Map<String, Object>> querySensorByDeviceType(@Param("devicetype") String devicetype);


    //查询设备下传感器(---)
    @Select(" select sm.PointName,sm.SNCode,sm.PointID,sm.DeviceID,sm.DeviceType,sm.DeviceTypeName,sm.slavecode,sm.pipeType, " +
            "                s.sensor_code,s.sensor_metric,sm.Center_X,sm.Center_Y,s.sensor_unit,s.sensor_name    " +
            "             from    ${tableName} sm   " +
            "             LEFT JOIN sc_type_sensor ts  on  sm.DeviceType=ts.device_type  " +
            "             LEFT JOIN sc_sensor_info s  on  s.sensor_code=ts.sensor_code   " +
            "              where   sm.DeviceID=#{deviceid}  ")
    List<Map<String,Object>> querySensorByDevice(@Param("tableName") String tableName,@Param("deviceid") String deviceid);

    //查询点位下传感器(---)
    @Select("  select   sm.PointName,sm.SNCode,sm.PointID,sm.DeviceID,sm.DeviceType,sm.DeviceTypeName," +
            "  s.sensor_code,s.sensor_metric,sm.Center_X,sm.Center_Y,s.sensor_unit,s.sensor_name   " +
            "  from   ${tableName}  sm " +
            "  LEFT JOIN   sc_type_sensor   ts on  sm.DeviceType=ts.device_type" +
            "  LEFT JOIN   sc_sensor_info  s   on  s.sensor_code=ts.sensor_code" +
            "  where sm.PointID=#{pointid}    ")
    List<Map<String,Object>> querySensorByPoint(@Param("tableName") String tableName,@Param("pointid") String pointid);

}
